﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Com.CMS263.BLL;
using Com.CMS263.Util;
using Com.CMS263.PO;
namespace Com.CMS263.Web.manage.ManageArtType
{
    public partial class AddExtAttribute : System.Web.UI.Page
    {
        ExtAttributeBLL eabll = new ExtAttributeBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!this.IsCallback)
            {
               int  id = int.Parse(Request["id"]);
               AttributeTypeBLL atbll = new AttributeTypeBLL();
               this.typeName.Text = atbll.GetAttributeById(id).typeName;
                BindExtAttr(id);
                this.hdfTypeId.Value = id.ToString();

            }
        }
        void BindExtAttr(int typeId)
        {
           this.ext.DataSource= eabll.GetExtAttributeByTypeId(typeId);
           this.ext.DataBind();
           
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string attrTxtName = this.txtAttrTxtName.Text;
            string attrName = this.txtAttrName.Text;
            string defaultValue = this.defaultValue.Text;
            string attrvalue = txtAttrValue.Text;
            int attrType = Convert.ToInt32(this.ddlAttrType.SelectedValue);
            int notNull = this.chkNotNull.Checked ? 1 : 0;
            int showInBack = this.chkShowInBack.Checked ? 1 : 0;
            int orderNum = Convert.ToInt32(this.txtOrderNum.Text);
            int typeId = Convert.ToInt32(this.hdfTypeId.Value);
           
            if (string.IsNullOrEmpty(attrTxtName))
            {
                StringUtil.Alert("请填写属性中文名","-1");
            }
            else if (string.IsNullOrEmpty(attrName))
            {
                StringUtil.Alert("请填写属性名", "-1");
            }
            if (eabll.Check(typeId, attrName))
            {
                StringUtil.Alert("同名属性已经存在，请选择其他属性名","-1");
                return;
            }

            ExtAttribute ea = new ExtAttribute();
            ea.attrName = attrName;
            ea.attrTxtName = attrTxtName;
            ea.attrType = attrType;
            ea.defaultValue = defaultValue;
            ea.notNull=notNull;
            ea.orderNum=orderNum;
            ea.attrValue = attrvalue;
            ea.showInBack=showInBack;
            ea.typeId=typeId;
            eabll.Add(ea);
            StringUtil.Alert("添加成功","AddExtAttribute.aspx?id="+this.hdfTypeId.Value);
        }

        protected void ddlAttrType_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
